/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.source.web.week;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.source.entity.week.EleSourceWeek;
import com.thinkgem.jeesite.modules.source.service.week.EleSourceWeekService;

/**
 * 星期资源管理Controller
 * @author ZC
 * @version 2017-06-19
 */
@Controller
@RequestMapping(value = "${adminPath}/source/week/eleSourceWeek")
public class EleSourceWeekController extends BaseController {

	@Autowired
	private EleSourceWeekService eleSourceWeekService;
	
	@ModelAttribute
	public EleSourceWeek get(@RequestParam(required=false) String id) {
		EleSourceWeek entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = eleSourceWeekService.get(id);
		}
		if (entity == null){
			entity = new EleSourceWeek();
		}
		return entity;
	}
	
	@RequiresPermissions("source:week:eleSourceWeek:view")
	@RequestMapping(value = {"list", ""})
	public String list(EleSourceWeek eleSourceWeek, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EleSourceWeek> page = eleSourceWeekService.findPage(new Page<EleSourceWeek>(request, response), eleSourceWeek); 
		model.addAttribute("page", page);
		return "modules/source/week/eleSourceWeekList";
	}

	@RequiresPermissions("source:week:eleSourceWeek:view")
	@RequestMapping(value = "form")
	public String form(EleSourceWeek eleSourceWeek, Model model) {
		model.addAttribute("eleSourceWeek", eleSourceWeek);
		return "modules/source/week/eleSourceWeekForm";
	}

	@RequiresPermissions("source:week:eleSourceWeek:edit")
	@RequestMapping(value = "save")
	public String save(EleSourceWeek eleSourceWeek, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, eleSourceWeek)){
			return form(eleSourceWeek, model);
		}
		eleSourceWeekService.save(eleSourceWeek);
		addMessage(redirectAttributes, "保存星期资源成功");
		return "redirect:"+Global.getAdminPath()+"/source/week/eleSourceWeek/?repage";
	}
	
	@RequiresPermissions("source:week:eleSourceWeek:edit")
	@RequestMapping(value = "delete")
	public String delete(EleSourceWeek eleSourceWeek, RedirectAttributes redirectAttributes) {
		eleSourceWeekService.delete(eleSourceWeek);
		addMessage(redirectAttributes, "删除星期资源成功");
		return "redirect:"+Global.getAdminPath()+"/source/week/eleSourceWeek/?repage";
	}

}